package com.bjh.controller;

import com.bjh.service.SystemService;
import com.bjh.util.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/agent/system")
public class SystemController extends BaseController {
    @Autowired
    private SystemService systemService;

    /**
     * 获取菜单列表
     * @return {@link Map}
     */
    @GetMapping("/getMenus")
    public Map<String, Object> getMenus () {
        logBefore(log, "++++++++++ 获取菜单列表 ++++++++++");
        try{
            List<?> menuList = new ArrayList<>(systemService.getMenus());
            logAfter(log);
            return returnSuccessWithData(menuList);
        }catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return returnResult(1, "获取菜单列表失败");
        }
    }
}
